# -*- coding: UTF-8 -*-  

from sqlalchemy import create_engine, Column
from sqlalchemy.orm import scoped_session, sessionmaker
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.dialects.mysql import VARCHAR, BIGINT, INTEGER, DATETIME
from sms import app

engine = create_engine(app.config['DATABASE_URI'], convert_unicode=True, pool_recycle=3600)
db_session = scoped_session(sessionmaker(autocommit=False, autoflush=False, bind=engine))
Model = declarative_base(name='Model')
Model.query = db_session.query_property()


#创建读写数据库操作模板

class Sms(Model):
	REQUEST = 0
	SUCCESS = 1
	ERROR = 2
	__tablename__ = 'yunpian_sms'

	id = Column(BIGINT(20), primary_key=True)
	client = Column(VARCHAR(255))
	mobile = Column(VARCHAR(255))
	content = Column(VARCHAR(255))
	createTime = Column(DATETIME)
	sendTime = Column(DATETIME)
	delaySeconds = Column(INTEGER(10))
	result = Column(VARCHAR(255))
	

	def __init__(self,client ,mobile, content, createTime,sendTime,delaySeconds, result):
		self.client = client
		self.mobile = mobile
		self.content = content
		self.createTime = createTime
		self.sendTime = sendTime
		self.delaySeconds = delaySeconds
		self.result = result

	def to_dict(self):
		return dict(id=self.id, mobile=self.mobile, content=self.content, schedule_time=self.schedule_time, status=self.status, source_ip=self.source_ip, request_header=self.request_header)

Model.metadata.create_all(engine)



# if __name__ == "__main__":
# 	
# 	sms = Sms(None,None,None,None,None,None,None,)
# 	
# 	print(sms)



